package team.bluepen.supermarket.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.bluepen.supermarket.entity.dto.UserLoginRequest;
import team.bluepen.supermarket.entity.dto.UserRegisterRequest;
import team.bluepen.supermarket.service.impl.LoginRegisterServiceImpl;

import java.util.Map;

/**
 * @author 狗崽
 */

@RestController
@RequestMapping("/user/account")
public class LoginRegisterController {

    @Autowired
    private LoginRegisterServiceImpl loginRegisterService;

    @PostMapping("/login/")
    public Map<String,String> Login(@RequestParam Map<String,String> map){
        String username =map.get("username");
        String password = map.get("password");
        return loginRegisterService.getToken(username,password);
    }

    @PostMapping("/register/")
    public Map<String,String> register(@RequestParam Map<String,String> map){
        String username = map.get("username");
        String password = map.get("password");
        String confirmedPassword = map.get("confirmedPassword");

        return loginRegisterService.register(username,password,confirmedPassword);
    }
}
